<?php

function uploadData($xmlData)
{
    $soapUrlStr = "http://211.88.20.132:8040/services/syncServiceStation?wsdl";
    $upMothodStr = 'syncServiceStationOperation';
    try {
        $client = new SoapClient($soapUrlStr);
        $client->soap_defencoding = 'utf-8';
        $client->decode_utf8 = false;
        $client->xml_encoding = 'utf-8';
        $param = array(
            'in' => $xmlData
        );
        $responseXmlStr = $client->__Call($upMothodStr, array(
            $param
        ));
        // $ret = 0;
        // if ($responseXmlStr->states == false) {
        // $ret = 1;
        // } else {
        // $ret = 0;
        // }
        return $responseXmlStr;
    } catch (SOAPFault $e) {
//         echo $e;
    }
}

function constructXmlData($userIdtxt, $codetxt, $nametxt, $countyTypetxt, $buyOrdertxt, $saleOrdertxt, $Commodity)
{
    $dom = new DOMDocument('1.0', 'utf-8');
    $serviceStation = $dom->createElement('serviceStation');
    $dom->appendChild($serviceStation);
    
    // 企业编码
    $userId = $dom->createElement('userId');
    $userIdText = $dom->createTextNode($userIdtxt);
    $userId->appendChild($userIdText);
    $serviceStation->appendChild($userId);
    // 报表日期
    $rptDate = $dom->createElement('rptDate');
    $rptDateText = $dom->createTextNode(date("Y-m-d"));
    $rptDate->appendChild($rptDateText);
    $serviceStation->appendChild($rptDate);
    // 各站点交易信息
    $serviceStationReport = $dom->createElement('serviceStationReport');
    $serviceStation->appendChild($serviceStationReport);
    // 站点编码
    $code = $dom->createElement('code');
    $codeText = $dom->createTextNode($codetxt);
    $code->appendChild($codeText);
    $serviceStationReport->appendChild($code);
    // 站点名称
    $name = $dom->createElement('name');
    $nameText = $dom->createTextNode($nametxt);
    $name->appendChild($nameText);
    $serviceStationReport->appendChild($name);
    // 站点类型 ：1县级服务中心 2乡镇级服务站 3村级服务站
    $countyType = $dom->createElement('countyType');
    $countyTypeText = $dom->createTextNode($countyTypetxt);
    $countyType->appendChild($countyTypeText);
    $serviceStationReport->appendChild($countyType);
    // 代买总订单数
    $buyOrder = $dom->createElement('buyOrder');
    $buyOrderText = $dom->createTextNode($buyOrdertxt);
    $buyOrder->appendChild($buyOrderText);
    $serviceStationReport->appendChild($buyOrder);
    // 代卖总订单数
    $saleOrder = $dom->createElement('saleOrder');
    $saleOrderText = $dom->createTextNode($saleOrdertxt);
    $saleOrder->appendChild($saleOrderText);
    $serviceStationReport->appendChild($saleOrder);
    
    foreach ($Commodity as $key => $val) {
        // 代买/代卖信息
        $serviceStationCommodity = $dom->createElement('serviceStationCommodity');
        $serviceStationReport->appendChild($serviceStationCommodity);
        // 商品类别
        $commId = $dom->createElement('commId');
        $commIdText = $dom->createTextNode($key);
        $commId->appendChild($commIdText);
        $serviceStationCommodity->appendChild($commId);
        // 金额
        $money = $dom->createElement('money');
        $moneyText = $dom->createTextNode($val);
        $money->appendChild($moneyText);
        $serviceStationCommodity->appendChild($money);
    }
    $xmlString = $dom->saveXML();
    return $xmlString;
}
?>